package com.gym.service.impl;


import com.gym.service.CaptchaService;
import com.gym.utils.service.JSONResult;
import com.gym.utils.service.RedisOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class CaptchaServiceImpl implements CaptchaService {


    @Autowired
    RedisOperator redisOperator;



    @Override
    public JSONResult validateCaptcha(String mobilePhone, String captcha) {
        String correctCode = redisOperator.get("sms1" + mobilePhone);
        if(correctCode==null){
            return  JSONResult.errorMsg("验证码过期");
        }
        if(!correctCode.equals(captcha)){
            return  JSONResult.errorMsg("验证码错误！");
        }
        redisOperator.del("sms" + mobilePhone);

        return JSONResult.success();
    }
}
